package com.qiangqiang.task.server.config;

import com.qiangqiang.task.server.websocket.MyHandler;
import com.qiangqiang.task.server.websocket.WebSocketInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;


/**
 * @program: task
 * @description:
 * @author: Sky.lin
 * @create: 2019-03-02 21:49
 **/
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(myHandler(), "myHandler/{ID}").setAllowedOrigins("*").addInterceptors(new WebSocketInterceptor());
    }

    public WebSocketHandler myHandler() {
        return new MyHandler();
    }

}